//
//  ColorConfig.swift
//  iOSProjectExtensionSwift
//
//  Created by Apple on 2020/1/11.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import Foundation
import UIKit
//色值
//官方主色
let kMainColor = hexStringToColor("#e74c3c");
//背景底色
let kBackGroundColor = hexStringToColor("#f8f8f8");
//线条颜色（重）
let kLineColor = hexStringToColor("#f2f2f2");
//线条颜色（浅）
let kLineColor_shallowly = hexStringToColor("#dcdde4");
//正文
let kText_color = hexStringToColor("#54698A");

let kTextColor = hexStringToColor("#fafcfa");

let K_0C2A59_color = hexStringToColor("#0C2A59");

let K_9EAABD_color = hexStringToColor("#9EAABD");

func ColorWithHex(_ value:String) -> UIColor {
    return hexStringToColor(value)
}

func hexStringToColor(_ stringToConvert:String) -> UIColor {
    return hexStringToColor(stringToConvert: stringToConvert, alpha: 1.0);
}
func hexStringToColor(stringToConvert:String, alpha:CGFloat) -> UIColor {
    var cString = stringToConvert.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines).uppercased();
    if cString.count<6 {
        return UIColor.black;
    }
    cString = String.init(describing: cString.suffix(6));
    if cString.count<6 {
        return UIColor.black;
    }
    var range = NSRange();
    range.location = 0;
    range.length = 2;
    let rStr = (cString as NSString).substring(with: range);
    range.location = 2;
    let gStr = (cString as NSString).substring(with: range);
    range.location = 4;
    let bStr = (cString as NSString).substring(with: range);
    var r: UInt64 = 0x0;
    var g: UInt64 = 0x0;
    var b: UInt64 = 0x0;
    Scanner.init(string: rStr).scanHexInt64(&r);
    Scanner.init(string: gStr).scanHexInt64(&g);
    Scanner.init(string: bStr).scanHexInt64(&b);
    return UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: alpha);
}
